package com.test.qnews.activity;

import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.test.qnews.R;
import java.util.HashMap;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;

/**
 * Created by dllo on 16/1/8.
 */
public class LoginActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected int setLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        ShareSDK.initSDK(this);
        findViewById(R.id.iv_back).setOnClickListener(this);
        findViewById(R.id.layout_qq).setOnClickListener(this);
        findViewById(R.id.layout_xinlang).setOnClickListener(this);
        findViewById(R.id.layout_weixin).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.layout_qq :
//                Toast.makeText(this, "qq登陆", Toast.LENGTH_SHORT).show();
                PlatformActionListener listener = new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                        Log.d("TrainFragment", platform.getDb().getUserId());
                        Log.d("TrainFragment", platform.getDb().getUserName());
                        platform.getDb().getUserIcon();
                        Log.d("TrainFragment", "授权成功");
                    }
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.d("TrainFragment", "授权失败");
                    }
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.d("TrainFragment", "取消授权");
                    }
                };
                Platform platform = ShareSDK.getPlatform(this, QQ.NAME);
                //判断是否已经授权过，如果授权，删除授权信息重新授权
                if (platform.isValid()) {
                    platform.removeAccount();
                }
                platform.setPlatformActionListener(listener);
//                platform.showUser(null);
                platform.authorize();
                break;
            case R.id.layout_xinlang :
                Toast.makeText(this, "新浪登陆", Toast.LENGTH_SHORT).show();
                break;
            case R.id.layout_weixin :
                Toast.makeText(this, "微信登陆", Toast.LENGTH_SHORT).show();
                break;
        }

    }


}
